package com.quickask.entity;

import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * Created by NaSa on 2015/9/23.
 */
@Entity
@Table(name = "asknow_answer_set", schema = "", catalog = "quickask")
@org.hibernate.annotations.Cache(usage= CacheConcurrencyStrategy.READ_WRITE, region = "com.quickask.entity.AsknowAnswerSetEntity")
public class AsknowAnswerSetEntity implements Serializable {
    private int answerId;  //答案主键
    private Timestamp answerTime;  //回答时间
    private Integer userId;  //回答者id
    private Integer questionId;  //问题id
    private Integer answerAdoptNum;  //答案被采纳数(或点赞数)
    private Byte answerIsAdopt;  //答案是否已被推荐为最佳答案,0否,1是,默认0
    private String answerContent;  //答案文字内容
    private String answerImageUrls;  //答案图片内容
    private String answerVoiceUrls;  //答案语音内容
    private Byte answerIsReport;  //答案是否被举报,0否,1是,默认0
    private Integer answerStars;  //答案的星数

    private AsknowAnswerLocationSetEntity asknowAnswerLocationSetEntity;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "answerId", nullable = false, insertable = true, updatable = true)
    public int getAnswerId() {
        return answerId;
    }

    public void setAnswerId(int answerId) {
        this.answerId = answerId;
    }

    @Basic
    @Column(name = "answerTime", nullable = true, insertable = true, updatable = true)
    public Timestamp getAnswerTime() {
        return answerTime;
    }

    public void setAnswerTime(Timestamp answerTime) {
        this.answerTime = answerTime;
    }

    @Basic
    @Column(name = "userId", nullable = false, insertable = true, updatable = true)
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "questionId", nullable = false, insertable = true, updatable = true)
    public Integer getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Integer questionId) {
        this.questionId = questionId;
    }

    @Basic
    @Column(name = "answerAdoptNum", nullable = true, insertable = true, updatable = true)
    public Integer getAnswerAdoptNum() {
        return answerAdoptNum;
    }

    public void setAnswerAdoptNum(Integer answerAdoptNum) {
        this.answerAdoptNum = answerAdoptNum;
    }

    @Basic
    @Column(name = "answerIsAdopt", nullable = true, insertable = true, updatable = true, scale = 1)
    public Byte getAnswerIsAdopt() {
        return answerIsAdopt;
    }

    public void setAnswerIsAdopt(Byte answerIsAdopt) {
        this.answerIsAdopt = answerIsAdopt;
    }

    @Basic
    @Column(name = "answerIsReport", nullable = true, insertable = true, updatable = true, scale = 1)
    public Byte getAnswerIsReport() {
        return answerIsReport;
    }

    public void setAnswerIsReport(Byte answerIsReport) {
        this.answerIsReport = answerIsReport;
    }

    @Basic
    @Column(name = "answerContent", nullable = true, insertable = true, updatable = true, length = 65535)
    public String getAnswerContent() {
        return answerContent;
    }

    public void setAnswerContent(String answerContent) {
        this.answerContent = answerContent;
    }

    @Basic
    @Column(name = "answerImageUrls", nullable = true, insertable = true, updatable = true, length = 10000)
    public String getAnswerImageUrls() {
        return answerImageUrls;
    }

    public void setAnswerImageUrls(String answerImageUrls) {
        this.answerImageUrls = answerImageUrls;
    }

    @Basic
    @Column(name = "answerVoiceUrls", nullable = true, insertable = true, updatable = true, length = 10000)
    public String getAnswerVoiceUrls() {
        return answerVoiceUrls;
    }

    public void setAnswerVoiceUrls(String answerVoiceUrls) {
        this.answerVoiceUrls = answerVoiceUrls;
    }

    @Basic
    @Column(name = "answerStars", nullable = true, insertable = true, updatable = true)
    public Integer getAnswerStars() {
        return answerStars;
    }

    public void setAnswerStars(Integer answerStars) {
        this.answerStars = answerStars;
    }

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "answerId")

    public AsknowAnswerLocationSetEntity getAsknowAnswerLocationSetEntity() {
        return asknowAnswerLocationSetEntity;
    }

    public void setAsknowAnswerLocationSetEntity(AsknowAnswerLocationSetEntity asknowAnswerLocationSetEntity) {
        this.asknowAnswerLocationSetEntity = asknowAnswerLocationSetEntity;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AsknowAnswerSetEntity)) return false;

        AsknowAnswerSetEntity that = (AsknowAnswerSetEntity) o;

        if (answerId != that.answerId) return false;
        if (answerTime != null ? !answerTime.equals(that.answerTime) : that.answerTime != null) return false;
        if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false;
        if (questionId != null ? !questionId.equals(that.questionId) : that.questionId != null) return false;
        if (answerAdoptNum != null ? !answerAdoptNum.equals(that.answerAdoptNum) : that.answerAdoptNum != null)
            return false;
        if (answerIsAdopt != null ? !answerIsAdopt.equals(that.answerIsAdopt) : that.answerIsAdopt != null)
            return false;
        if (answerContent != null ? !answerContent.equals(that.answerContent) : that.answerContent != null)
            return false;
        if (answerImageUrls != null ? !answerImageUrls.equals(that.answerImageUrls) : that.answerImageUrls != null)
            return false;
        if (answerVoiceUrls != null ? !answerVoiceUrls.equals(that.answerVoiceUrls) : that.answerVoiceUrls != null)
            return false;
        if (answerIsReport != null ? !answerIsReport.equals(that.answerIsReport) : that.answerIsReport != null)
            return false;
        if (answerStars != null ? !answerStars.equals(that.answerStars) : that.answerStars != null) return false;
        return !(asknowAnswerLocationSetEntity != null ? !asknowAnswerLocationSetEntity.equals(that.asknowAnswerLocationSetEntity) : that.asknowAnswerLocationSetEntity != null);

    }

    @Override
    public int hashCode() {
        int result = answerId;
        result = 31 * result + (answerTime != null ? answerTime.hashCode() : 0);
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (questionId != null ? questionId.hashCode() : 0);
        result = 31 * result + (answerAdoptNum != null ? answerAdoptNum.hashCode() : 0);
        result = 31 * result + (answerIsAdopt != null ? answerIsAdopt.hashCode() : 0);
        result = 31 * result + (answerContent != null ? answerContent.hashCode() : 0);
        result = 31 * result + (answerImageUrls != null ? answerImageUrls.hashCode() : 0);
        result = 31 * result + (answerVoiceUrls != null ? answerVoiceUrls.hashCode() : 0);
        result = 31 * result + (answerIsReport != null ? answerIsReport.hashCode() : 0);
        result = 31 * result + (answerStars != null ? answerStars.hashCode() : 0);
        result = 31 * result + (asknowAnswerLocationSetEntity != null ? asknowAnswerLocationSetEntity.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "AsknowAnswerSetEntity{" +
                "answerId=" + answerId +
                ", answerTime=" + answerTime +
                ", userId=" + userId +
                ", questionId=" + questionId +
                ", answerAdoptNum=" + answerAdoptNum +
                ", answerIsAdopt=" + answerIsAdopt +
                ", answerContent='" + answerContent + '\'' +
                ", answerImageUrls='" + answerImageUrls + '\'' +
                ", answerVoiceUrls='" + answerVoiceUrls + '\'' +
                ", answerIsReport=" + answerIsReport +
                ", answerStars=" + answerStars +
                ", asknowAnswerLocationSetEntity=" + asknowAnswerLocationSetEntity +
                '}';
    }
}
